package com.bnz.controller;


import com.bnz.entity.PageResult;
import com.bnz.entity.R;
import com.bnz.entity.Student;
import com.bnz.service.StudentService;
import com.bnz.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

//@Controller
//@ResponseBody
@RestController
@RequestMapping("/student")
public class StudentController2 {

    @Autowired
    private StudentService studentService;

    @GetMapping("/list")
    public R list(){
        List<Student> studentList=studentService.findAll();

        return R.ok().data("list",studentList);
    }

    @GetMapping("findByPage/{page}/{pageSize}")
    public R findByPage(@PathVariable int page,@PathVariable int pageSize){
        PageResult<String > pr=studentService.findByPage(page,pageSize);

        return R.ok().data("pr",pr);

    }

    @PostMapping("search/{page}/{pageSize}")
    public R search(@PathVariable int page,
                    @PathVariable int pageSize,
                    @RequestBody(required = false) StudentVo vo){

        PageResult<String > pr=studentService.search(page,pageSize,vo);

        return R.ok().data("pr",pr);
    }

    @RequestMapping("add")
    public R add(@RequestBody Student student){
        studentService.add(student);
        return R.ok().message("添加学生成功！");
    }

    @RequestMapping("update")
    public R update(@RequestBody Student student){
        studentService.update(student);
        return R.ok().message("修改学生成功！");
    }

    @DeleteMapping("delete/{sids}")
    public R delete(@PathVariable Integer[] sids){
        studentService.delete(sids);
        return R.ok().message("删除学生成功！");
    }



}
